import os
import pickle
import shutil
print('start')
os.system('D:\\MFT\\e2open_staging\\e2open_staging.ffs_batch')
print('freefilesync end')


# 保存set集合到文件
def save_set_to_file(file_path, set_to_save):
    with open(file_path, 'wb') as file:
        pickle.dump(set_to_save, file)

# 从文件中读取set集合
def load_set_from_file(file_path):
    with open(file_path, 'rb') as file:
        loaded_set = pickle.load(file)
        return loaded_set






def folder_compare(file,folder):
    # 从文件中读取set
    #file_path = "set_data.pkl"
    file_path=file
    loaded_set = load_set_from_file(file_path)
    #print("pre file list is ",loaded_set)
    dirlist=set(os.listdir(folder))
    #print("cur file list is ",dirlist)
    result_set = dirlist.difference(loaded_set)
    # 保存set到文件
    save_set_to_file(file, dirlist)
    return result_set
    

original_folder='D:\\MFT\\e2open_staging\\input\\'
dest_folder='D:\\MFT\\e2open_staging\\mes\\1.待处理\\'
filenamelist="D:\\MFT\\e2open_staging\\filenames.pkl"
diff=folder_compare(filenamelist,original_folder)
print('diff',diff)
for item in diff:
    print('copy',original_folder+item, 'to',dest_folder+item)
    shutil.copyfile(original_folder+item, dest_folder+item)
print('end')
